<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;
/**
* 会员管理控制器
*/
class UserController extends CommonController
{
	public function __init()
	{
		//如果没有登陆
		if (!isset($_SESSION['username'])||!isset($_SESSION['uid'])) {
			$str=<<<str
<script>
parent.location.href="index.php?m=Admin&c=Login";
</script>
str;
			echo $str;exit;
		}
	}
	//修改密码
	public function changePwd()
	{
		if (IS_AJAX) {
			//接收旧密码
			$password=Q('post.password');
			//实例化模型
			$model=new \Common\Model\User;
			//把旧密码加密
			$password=$model->encrypt($_SESSION['username'],$password);
			//判断旧密码是否正确
			$data=$model->where("uid={$_SESSION['uid']}")->find();
			if ($data['password']!=$password) {
				echo json_encode(array('status'=>false,'message'=>'旧密码错误'));
				exit;
			}
			//判断两次密码是否相同
			$newPassword=Q('post.newPassword');
			$confirmPassword=Q('post.confirmPassword');
			if($newPassword!=$confirmPassword){
				echo json_encode(array('status'=>false,'message'=>'两次密码不一样'));
				exit;
			}
			//修改密码

			$password=$model->encrypt($_SESSION['username'],$newPassword);
			$model->where("uid={$_SESSION['uid']}")->save(array('password'=>$password));
			//修改完成直接重新登陆
			session_unset();
			session_destroy();
			echo json_encode(array('status'=>true,'message'=>'修改成功'));
			exit;
		}
		View::make();
	}
}
 ?>